ひとりNavigation API Advent Calendar 09日目
https://gyazo.com/144e22e5c7faad64d3b2e9216aff59cc
これはひとりNavigation API Advent Calendarの9日目です。
TypeScriptにおけるNavigation APIとHistory APIについての型定義を見ていきます
https://github.com/microsoft/TypeScript-DOM-lib-generator/blob/main/baselines/dom.generated.d.ts より参考
Navigation API
code:ts
interface Navigation extends EventTarget {
/**
* The **activation** read-only property of the Navigation interface returns a NavigationActivation object containing information about the most recent cross-document navigation, which "activated" this Document. The property will stay constant during same-document navigations.
*
* MDN Reference(https://developer.mozilla.org/docs/Web/API/Navigation/activation)
*/
readonly activation: NavigationActivation | null;
/**
* The **canGoBack** read-only property of the Navigation interface returns true if it is possible to navigate backwards in the navigation history (i.e., the currentEntry is not the first one in the history entry list), and false if it is not.
*
* MDN Reference(https://developer.mozilla.org/docs/Web/API/Navigation/canGoBack)
*/
readonly canGoBack: boolean;
/**
* The **canGoForward** read-only property of the Navigation interface returns true if it is possible to navigate forwards in the navigation history (i.e., the currentEntry is not the last one in the history entry list), and false if it is not.
*
* MDN Reference(https://developer.mozilla.org/docs/Web/API/Navigation/canGoForward)
*/
readonly canGoForward: boolean;
/**
* The **currentEntry** read-only property of the Navigation interface returns a NavigationHistoryEntry object representing the location the user is currently navigated to right now.
*
* MDN Reference(https://developer.mozilla.org/docs/Web/API/Navigation/currentEntry)
*/
readonly currentEntry: NavigationHistoryEntry | null;
/**
* The **transition** read-only property of the Navigation interface returns a NavigationTransition object representing the status of an in-progress navigation, which can be used to track it.
*
* MDN Reference(https://developer.mozilla.org/docs/Web/API/Navigation/transition)
*/
readonly transition: NavigationTransition | null;
/**
* The **back()** method of the Navigation interface navigates backwards by one entry in the navigation history.
*
* MDN Reference(https://developer.mozilla.org/docs/Web/API/Navigation/back)
*/
back(options?: NavigationOptions): NavigationResult;
/**
* The **entries()** method of the Navigation interface returns an array of NavigationHistoryEntry objects representing all existing history entries.
*
* MDN Reference(https://developer.mozilla.org/docs/Web/API/Navigation/entries)
*/
entries(): NavigationHistoryEntry[];
/**
* The **forward()** method of the Navigation interface navigates forwards by one entry in the navigation history.
*
* MDN Reference(https://developer.mozilla.org/docs/Web/API/Navigation/forward)
*/
forward(options?: NavigationOptions): NavigationResult;
/**
* The **navigate()** method of the Navigation interface navigates to a specific URL, updating any provided state in the history entries list.
*
* MDN Reference(https://developer.mozilla.org/docs/Web/API/Navigation/navigate)
*/
navigate(url: string | URL, options?: NavigationNavigateOptions): NavigationResult;
/**
* The **reload()** method of the Navigation interface reloads the current URL, updating any provided state in the history entries list.
*
* MDN Reference(https://developer.mozilla.org/docs/Web/API/Navigation/reload)
*/
reload(options?: NavigationReloadOptions): NavigationResult;
/**
* The **traverseTo()** method of the Navigation interface navigates to the NavigationHistoryEntry identified by the given key.
*
* MDN Reference(https://developer.mozilla.org/docs/Web/API/Navigation/traverseTo)
*/
traverseTo(key: string, options?: NavigationOptions): NavigationResult;
/**
* The **updateCurrentEntry()** method of the Navigation interface updates the state of the currentEntry; used in cases where the state change will be independent of a navigation or reload.
*
* MDN Reference(https://developer.mozilla.org/docs/Web/API/Navigation/updateCurrentEntry)
*/
updateCurrentEntry(options: NavigationUpdateCurrentEntryOptions): void;
}
declare var Navigation: {
prototype: Navigation;
new(): Navigation;
};
code:typescript
interface NavigateEvent extends Event {
/**
* The **canIntercept** read-only property of the NavigateEvent interface returns true if the navigation can be intercepted and have its URL rewritten, or false otherwise
*
* MDN Reference(https://developer.mozilla.org/docs/Web/API/NavigateEvent/canIntercept)
*/
readonly canIntercept: boolean;
/**
* The **destination** read-only property of the NavigateEvent interface returns a NavigationDestination object representing the destination being navigated to.
*
* MDN Reference(https://developer.mozilla.org/docs/Web/API/NavigateEvent/destination)
*/
readonly destination: NavigationDestination;
/**
* The **downloadRequest** read-only property of the NavigateEvent interface returns the filename of the file requested for download, in the case of a download navigation (e.g., an <a> or <area> element with a download attribute), or null otherwise.
*
* MDN Reference(https://developer.mozilla.org/docs/Web/API/NavigateEvent/downloadRequest)
*/
readonly downloadRequest: string | null;
/**
* The **formData** read-only property of the NavigateEvent interface returns the FormData object representing the submitted data in the case of a POST form submission, or null otherwise.
*
* MDN Reference(https://developer.mozilla.org/docs/Web/API/NavigateEvent/formData)
*/
readonly formData: FormData | null;
/**
* The **hasUAVisualTransition** read-only property of the NavigateEvent interface returns true if the user agent performed a visual transition for this navigation before dispatching this event, or false otherwise.
*
* MDN Reference(https://developer.mozilla.org/docs/Web/API/NavigateEvent/hasUAVisualTransition)
*/
readonly hasUAVisualTransition: boolean;
/**
* The **hashChange** read-only property of the NavigateEvent interface returns true if the navigation is a fragment navigation (i.e., to a fragment identifier in the same document), or false otherwise.
*
* MDN Reference(https://developer.mozilla.org/docs/Web/API/NavigateEvent/hashChange)
*/
readonly hashChange: boolean;
/**
* The **info** read-only property of the NavigateEvent interface returns the info data value passed by the initiating navigation operation (e.g., Navigation.back(), or Navigation.navigate()), or undefined if no info data was passed.
*
* MDN Reference(https://developer.mozilla.org/docs/Web/API/NavigateEvent/info)
*/
readonly info: any;
/**
* The **navigationType** read-only property of the NavigateEvent interface returns the type of the navigation — push, reload, replace, or traverse.
*
* MDN Reference(https://developer.mozilla.org/docs/Web/API/NavigateEvent/navigationType)
*/
readonly navigationType: NavigationType;
/**
* The **signal** read-only property of the NavigateEvent interface returns an AbortSignal, which will become aborted if the navigation is cancelled (e.g., by the user pressing the browser's "Stop" button, or another navigation starting and thus cancelling the ongoing one).
*
* MDN Reference(https://developer.mozilla.org/docs/Web/API/NavigateEvent/signal)
*/
readonly signal: AbortSignal;
/**
* The **sourceElement** read-only property of the NavigateEvent interface returns an Element object representing the initiating element, in cases where the navigation was initiated by an element.
*
* MDN Reference(https://developer.mozilla.org/docs/Web/API/NavigateEvent/sourceElement)
*/
readonly sourceElement: Element | null;
/**
* The **userInitiated** read-only property of the NavigateEvent interface returns true if the navigation was initiated by the user (e.g., by clicking a link, submitting a form, or pressing the browser's "Back"/"Forward" buttons), or false otherwise.
*
* MDN Reference(https://developer.mozilla.org/docs/Web/API/NavigateEvent/userInitiated)
*/
readonly userInitiated: boolean;
/**
* The **intercept()** method of the NavigateEvent interface intercepts this navigation, turning it into a same-document navigation to the destination URL.
*
* MDN Reference(https://developer.mozilla.org/docs/Web/API/NavigateEvent/intercept)
*/
intercept(options?: NavigationInterceptOptions): void;
/**
* The **scroll()** method of the NavigateEvent interface can be called to manually trigger the browser-driven scrolling behavior that occurs in response to the navigation, if you want it to happen before the navigation handling has completed.
*
* MDN Reference(https://developer.mozilla.org/docs/Web/API/NavigateEvent/scroll)
*/
scroll(): void;
}
declare var NavigateEvent: {
prototype: NavigateEvent;
new(type: string, eventInitDict: NavigateEventInit): NavigateEvent;
};
code:ts
interface NavigationActivation {
/**
* The **entry** read-only property of the NavigationActivation interface contains a NavigationHistoryEntry object representing the history entry for the inbound ("to") document in the navigation. This is equivalent to the Navigation.currentEntry property at the moment the inbound document was activated.
*
* MDN Reference(https://developer.mozilla.org/docs/Web/API/NavigationActivation/entry)
*/
readonly entry: NavigationHistoryEntry;
/**
* The **from** read-only property of the NavigationActivation interface contains a NavigationHistoryEntry object representing the history entry for the outgoing ("from") document in the navigation.
*
* MDN Reference(https://developer.mozilla.org/docs/Web/API/NavigationActivation/from)
*/
readonly from: NavigationHistoryEntry | null;
/**
* The **navigationType** read-only property of the NavigationActivation interface contains a string indicating the type of navigation.
*
* MDN Reference(https://developer.mozilla.org/docs/Web/API/NavigationActivation/navigationType)
*/
readonly navigationType: NavigationType;
}
declare var NavigationActivation: {
prototype: NavigationActivation;
new(): NavigationActivation;
};
code:ts
interface NavigationCurrentEntryChangeEvent extends Event {
/**
* The **from** read-only property of the NavigationCurrentEntryChangeEvent interface returns the NavigationHistoryEntry that was navigated from.
*
* MDN Reference(https://developer.mozilla.org/docs/Web/API/NavigationCurrentEntryChangeEvent/from)
*/
readonly from: NavigationHistoryEntry;
/**
* The **navigationType** read-only property of the NavigationCurrentEntryChangeEvent interface returns the type of the navigation that resulted in the change. The property may be null if the change occurs due to Navigation.updateCurrentEntry().
*
* MDN Reference(https://developer.mozilla.org/docs/Web/API/NavigationCurrentEntryChangeEvent/navigationType)
*/
readonly navigationType: NavigationType | null;
}
declare var NavigationCurrentEntryChangeEvent: {
prototype: NavigationCurrentEntryChangeEvent;
new(type: string, eventInitDict: NavigationCurrentEntryChangeEventInit): NavigationCurrentEntryChangeEvent;
};
code:ts
interface NavigationDestination {
/**
* The **id** read-only property of the NavigationDestination interface returns the id value of the destination NavigationHistoryEntry if the NavigateEvent.navigationType is traverse, or an empty string otherwise.
*
* MDN Reference(https://developer.mozilla.org/docs/Web/API/NavigationDestination/id)
*/
readonly id: string;
/**
* The **index** read-only property of the NavigationDestination interface returns the index value of the destination NavigationHistoryEntry if the NavigateEvent.navigationType is traverse, or -1 otherwise.
*
* MDN Reference(https://developer.mozilla.org/docs/Web/API/NavigationDestination/index)
*/
readonly index: number;
/**
* The **key** read-only property of the NavigationDestination interface returns the key value of the destination NavigationHistoryEntry if the NavigateEvent.navigationType is traverse, or an empty string otherwise.
*
* MDN Reference(https://developer.mozilla.org/docs/Web/API/NavigationDestination/key)
*/
readonly key: string;
/**
* The **sameDocument** read-only property of the NavigationDestination interface returns true if the navigation is to the same document as the current Document value, or false otherwise.
*
* MDN Reference(https://developer.mozilla.org/docs/Web/API/NavigationDestination/sameDocument)
*/
readonly sameDocument: boolean;
/**
* The **url** read-only property of the NavigationDestination interface returns the URL being navigated to.
*
* MDN Reference(https://developer.mozilla.org/docs/Web/API/NavigationDestination/url)
*/
readonly url: string;
/**
* The **getState()** method of the NavigationDestination interface returns a clone of the developer-supplied state associated with the destination NavigationHistoryEntry, or navigation operation (e.g., navigate()) as appropriate.
*
* MDN Reference(https://developer.mozilla.org/docs/Web/API/NavigationDestination/getState)
*/
getState(): any;
}
declare var NavigationDestination: {
prototype: NavigationDestination;
new(): NavigationDestination;
};
code:ts
interface NavigationHistoryEntryEventMap {
"dispose": Event;
}
code:ts
interface NavigationHistoryEntry extends EventTarget {
/**
* The **id** read-only property of the NavigationHistoryEntry interface returns the id of the history entry, or an empty string if current document is not fully active. This is a unique, UA-generated value that always represents a specific history entry, useful to correlate it with an external resource such as a storage cache.
*
* MDN Reference(https://developer.mozilla.org/docs/Web/API/NavigationHistoryEntry/id)
*/
readonly id: string;
/**
* The **index** read-only property of the NavigationHistoryEntry interface returns the index of the history entry in the history entries list (that is, the list returned by Navigation.entries()), or -1 if the entry does not appear in the list or if current document is not fully active.
*
* MDN Reference(https://developer.mozilla.org/docs/Web/API/NavigationHistoryEntry/index)
*/
readonly index: number;
/**
* The **key** read-only property of the NavigationHistoryEntry interface returns the key of the history entry, or an empty string if current document is not fully active. This is a unique, UA-generated value that represents the history entry's slot in the entries list. It is used to navigate that particular slot via Navigation.traverseTo(). The key will be reused by other entries that replace the entry in the list (that is, if the NavigateEvent.navigationType is replace).
*
* MDN Reference(https://developer.mozilla.org/docs/Web/API/NavigationHistoryEntry/key)
*/
readonly key: string;
/** MDN Reference(https://developer.mozilla.org/docs/Web/API/NavigationHistoryEntry/dispose_event) */
ondispose: ((this: NavigationHistoryEntry, ev: Event) => any) | null;
/**
* The **sameDocument** read-only property of the NavigationHistoryEntry interface returns true if this history entry is for the same document as the current Document value and current document is fully active, or false otherwise.
*
* MDN Reference(https://developer.mozilla.org/docs/Web/API/NavigationHistoryEntry/sameDocument)
*/
readonly sameDocument: boolean;
/**
* The **url** read-only property of the NavigationHistoryEntry interface returns the absolute URL of this history entry. If the entry corresponds to a different Document than the current one (like sameDocument property is false), and that Document was fetched with a Referrer-Policy header set to no-referrer or origin, the property returns null. If current document is not fully active, it returns an empty string.
*
* MDN Reference(https://developer.mozilla.org/docs/Web/API/NavigationHistoryEntry/url)
*/
readonly url: string | null;
/**
* The **getState()** method of the NavigationHistoryEntry interface returns a clone of the developer-supplied state associated with this history entry.
*
* MDN Reference(https://developer.mozilla.org/docs/Web/API/NavigationHistoryEntry/getState)
*/
getState(): any;
addEventListener<K extends keyof NavigationHistoryEntryEventMap>(type: K, listener: (this: NavigationHistoryEntry, ev: NavigationHistoryEntryEventMapK) => any, options?: boolean | AddEventListenerOptions): void;
addEventListener(type: string, listener: EventListenerOrEventListenerObject, options?: boolean | AddEventListenerOptions): void;
removeEventListener<K extends keyof NavigationHistoryEntryEventMap>(type: K, listener: (this: NavigationHistoryEntry, ev: NavigationHistoryEntryEventMapK) => any, options?: boolean | EventListenerOptions): void;
removeEventListener(type: string, listener: EventListenerOrEventListenerObject, options?: boolean | EventListenerOptions): void;
}
declare var NavigationHistoryEntry: {
prototype: NavigationHistoryEntry;
new(): NavigationHistoryEntry;
};
code:ts
interface NavigationPrecommitController {
/**
* The **redirect()** method of the NavigationPrecommitController interface redirects the browser to a specified URL and specifies history behavior and any desired state information.
*
* MDN Reference(https://developer.mozilla.org/docs/Web/API/NavigationPrecommitController/redirect)
*/
redirect(url: string | URL, options?: NavigationNavigateOptions): void;
}
declare var NavigationPrecommitController: {
prototype: NavigationPrecommitController;
new(): NavigationPrecommitController;
};
code:ts
interface NavigationPreloadManager {
/**
* The **disable()** method of the NavigationPreloadManager interface halts the automatic preloading of service-worker-managed resources previously started using enable() It returns a promise that resolves with undefined.
*
* MDN Reference(https://developer.mozilla.org/docs/Web/API/NavigationPreloadManager/disable)
*/
disable(): Promise<void>;
/**
* The **enable()** method of the NavigationPreloadManager interface is used to enable preloading of resources managed by the service worker. It returns a promise that resolves with undefined.
*
* MDN Reference(https://developer.mozilla.org/docs/Web/API/NavigationPreloadManager/enable)
*/
enable(): Promise<void>;
/**
* The **getState()** method of the NavigationPreloadManager interface returns a Promise that resolves to an object with properties that indicate whether preload is enabled and what value will be sent in the Service-Worker-Navigation-Preload HTTP header.
*
* MDN Reference(https://developer.mozilla.org/docs/Web/API/NavigationPreloadManager/getState)
*/
getState(): Promise<NavigationPreloadState>;
/**
* The **setHeaderValue()** method of the NavigationPreloadManager interface sets the value of the Service-Worker-Navigation-Preload header that will be sent with requests resulting from a fetch() operation made during service worker navigation preloading. It returns an empty Promise that resolves with undefined.
*
* MDN Reference(https://developer.mozilla.org/docs/Web/API/NavigationPreloadManager/setHeaderValue)
*/
setHeaderValue(value: string): Promise<void>;
}
declare var NavigationPreloadManager: {
prototype: NavigationPreloadManager;
new(): NavigationPreloadManager;
};
code:ts
interface NavigationTransition {
readonly committed: Promise<void>;
/**
* The **finished** read-only property of the NavigationTransition interface returns a Promise that fulfills at the same time the navigatesuccess event fires, or rejects at the same time the navigateerror event fires.
*
* MDN Reference(https://developer.mozilla.org/docs/Web/API/NavigationTransition/finished)
*/
readonly finished: Promise<void>;
/**
* The **from** read-only property of the NavigationTransition interface returns the NavigationHistoryEntry that the transition is coming from.
*
* MDN Reference(https://developer.mozilla.org/docs/Web/API/NavigationTransition/from)
*/
readonly from: NavigationHistoryEntry;
/**
* The **navigationType** read-only property of the NavigationTransition interface returns the type of the ongoing navigation.
*
* MDN Reference(https://developer.mozilla.org/docs/Web/API/NavigationTransition/navigationType)
*/
readonly navigationType: NavigationType;
}
declare var NavigationTransition: {
prototype: NavigationTransition;
new(): NavigationTransition;
};
navigationとかwindow.navigationはまだ登録されていない
https://gyazo.com/09c729fadc77fb05324df80e28eeba72 https://www.typescriptlang.org/play/?ts=5.9.3#code/HYQwbglg5iAuEHtgDoQBM0FEwFNiwBkIBnWPHAJwAoAiUSGMmgGgAIqdd8BKVgXgB8rAN4AoVqwD0k1pgAeEWKxwgKAGwCerCADNWsABYlW9aHETBWxAwgCuatMADkSgEY5t+SgGMcABzI0ZnEpGRxkKGRtPUMPU0YLbWJWbwoEYmIAWgQKaAhgNhzWEFY0BAB3YDUEdFYKHABHWxxSEN12azsHADkEWABJLwpfAI4uWG5eethbCmAAblEQ7yRSVlm1fhMcctYAVQAlAjG8WGQ0FvhQeCRkDe5Ftr0qDeQ-OANQAFtw0lVYYgAdUUBlokn+EG8ahakhokxEIQknFOyHyZGG-lgVDEElxxWIGmA3lYBhAwDQ0OovBxeNx0lYABUDB5DgQSSBkiA1PV0FpvKTgFAcEErAgrDZdiU-GoQL4bA5KKxykZoYjafSdDhYPz8lB9MztrsVl58GxiLZ+fjilY-PlgIqitV0LrWO8hWq8fVyZQAIIUeBQnAABRAQqDMrlCAVVMetLpMgAYlrLbFDSkkGR8MVyaUSNKQFplXg6io0BoPbjjWsIYGAMIZ05bEDlECKVhC2B+gPQ+smrGvd6Gb44B4ViRei4ULuQ6EhoVUGs9hs8RZxgC+wTxa9HEjXom3iyAA
History API
code:ts
/**
* The **History** interface of the History API allows manipulation of the browser session history, that is the pages visited in the tab or frame that the current page is loaded in.
*
* MDN Reference(https://developer.mozilla.org/docs/Web/API/History)
*/
interface History {
/**
* The **length** read-only property of the History interface returns an integer representing the number of entries in the session history, including the currently loaded page.
*
* MDN Reference(https://developer.mozilla.org/docs/Web/API/History/length)
*/
readonly length: number;
/**
* The **scrollRestoration** property of the History interface allows web applications to explicitly set default scroll restoration behavior on history navigation.
*
* MDN Reference(https://developer.mozilla.org/docs/Web/API/History/scrollRestoration)
*/
scrollRestoration: ScrollRestoration;
/**
* The **state** read-only property of the History interface returns a value representing the state at the top of the history stack. This is a way to look at the state without having to wait for a popstate event.
*
* MDN Reference(https://developer.mozilla.org/docs/Web/API/History/state)
*/
readonly state: any;
/**
* The **back()** method of the History interface causes the browser to move back one page in the session history.
*
* MDN Reference(https://developer.mozilla.org/docs/Web/API/History/back)
*/
back(): void;
/**
* The **forward()** method of the History interface causes the browser to move forward one page in the session history. It has the same effect as calling history.go(1).
*
* MDN Reference(https://developer.mozilla.org/docs/Web/API/History/forward)
*/
forward(): void;
/**
* The **go()** method of the History interface loads a specific page from the session history. You can use it to move forwards and backwards through the history depending on the value of a parameter.
*
* MDN Reference(https://developer.mozilla.org/docs/Web/API/History/go)
*/
go(delta?: number): void;
/**
* The **pushState()** method of the History interface adds an entry to the browser's session history stack.
*
* MDN Reference(https://developer.mozilla.org/docs/Web/API/History/pushState)
*/
pushState(data: any, unused: string, url?: string | URL | null): void;
/**
* The **replaceState()** method of the History interface modifies the current history entry, replacing it with the state object and URL passed in the method parameters. This method is particularly useful when you want to update the state object or URL of the current history entry in response to some user action.
*
* MDN Reference(https://developer.mozilla.org/docs/Web/API/History/replaceState)
*/
replaceState(data: any, unused: string, url?: string | URL | null): void;
}
declare var History: {
prototype: History;
new(): History;
};
code:ts
type ScrollRestoration = "auto" | "manual";
参考記事
lib.dom.d.tsがどのように更新されるか調べてみた
https://github.com/microsoft/TypeScript-DOM-lib-generator
browser-compat-dataをベースに生成されている
Baseline基準でやらんのかなって思ったりしたyamanoku.icon